package guilddao

import (
	"context"
	"fmt"
	"github.com/gogf/gf/v2/frame/g"
	"xr-game-server/core/cache"
	"xr-game-server/entity"
)

var blacklistCache *cache.CacheMgr

func initBlackList() {
	blacklistCache = cache.NewCacheMgr()
}

func GetBlackListBy(guildId uint64, roleId uint64) *entity.GuildBlackList {
	blackList := blacklistCache.GetData(fmt.Sprintf("%v_%v", guildId, roleId), func(ctx context.Context) (value interface{}, err error) {
		var ret *entity.GuildBlackList
		g.Model(string(entity.TbGuildBlackList)).Unscoped().Where(g.Map{
			string(entity.GuildBlackListGuildId): guildId,
			string(entity.GuildBlackListRoleId):  roleId,
		}).Scan(&ret)
		if ret == nil {
			ret = entity.NewGuildBlackList(guildId, roleId)
		}
		return ret, nil
	})
	return blackList.(*entity.GuildBlackList)
}
